/*
 *
 * Copyright 2017-2018. All rights reserved.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.loveprogrammer.eternity.enums;

import com.loveprogrammer.eternity.model.product.Equipment;
import com.loveprogrammer.eternity.model.product.equipment.Weapon;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

/**
 * 装备的位置
 *
 * @author eric
 * @version 1.0.0
 */
public enum EquipmentEnum {

    WEAPON("weapon", "武器", Equipment.class,1),
    SHIELD("shield", "盾牌", Equipment.class,2),
    SHOES("shoes", "鞋子", Equipment.class,3),
    HELMET("helmet", "头盔", Equipment.class,4),
    GLOVES("gloves", "手套", Equipment.class,5),
    NECKLACE("necklace", "项链", Equipment.class,6),
    TALISMAN("talisman", "护身符", Equipment.class,7),
    LEFTRING("leftRing", "左戒", Equipment.class,8),
    RIGHTRING("rightRing", "右戒", Equipment.class,9),
    LEGARMOR("legArmor", "腿甲", Equipment.class,10),
    BELT("belt", "腰带", Equipment.class,11),
    BARCER("barcer", "护臂", Equipment.class,12),
    SHOULDER("shoulder", "肩甲", Equipment.class,13),
    BREASTPLATE("breastplate", "胸甲", Equipment.class,14),
    UNKOWN("unkown", "其他", Equipment.class,15);

    public final static int total = 14;

    private String code;

    private String desc;

    private Class equipmentClass;

    private int posNum;

    EquipmentEnum(String code, String desc, Class equipmentClass, int posNum) {
        this.code = code;
        this.desc = desc;
        this.equipmentClass = equipmentClass;
        this.posNum = posNum;
    }

    public static EquipmentEnum getByCode(String code){
        Optional<EquipmentEnum> optional =
                Arrays.stream(EquipmentEnum.values())
                        .filter(v -> Objects.equals(v.getCode(), code))
                        .findFirst();

        return optional.orElse(EquipmentEnum.UNKOWN);
    }

    public static EquipmentEnum getByPosNum(int posNum){
        Optional<EquipmentEnum> optional =
                Arrays.stream(EquipmentEnum.values())
                        .filter(v -> v.getPosNum() == posNum)
                        .findFirst();

        return optional.orElse(EquipmentEnum.UNKOWN);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Class getEquipmentClass() {
        return equipmentClass;
    }

    public int getPosNum() {
        return posNum;
    }
}
